package com.lime49.lockcrypt;
//import java.net.*;

import java.net.URL;


public class UtilsTest extends Thread {
    public UtilsTest() {
        
    }
    public void run() {
        //stripURLs();
        //wildcardURLs();
    }

    public static void stripURLs() {
        String[] u = {
            "file://C:/Users/Echilon/Documents/Coding/LockCryptFF/test.html",
            "file://C:/Users/Echilon/Documents/Coding/LockCryptFF/test.html?k1=v1&v2=v2",
            "http://www.google.com",
            "http://www.google.com/index.php?hl=en",
            "http://www.google.com/?hl=en",
            "http://www.google.com/hl-en/?somevar=something",
            "http://amazon.com/"
        };
        for(String url : u) {
            System.out.println(url+"\t-\t"+Utils.stripURL(url, true));
        }
    }

    public static void wildcardURLs() {
        String[] currentURLs = {
            "http://www.google.com/",
            "http://google.com/",
            "http://google.com/blah",
            "ftp://ftp.google.com/",
            "ftp://google.co.uk/",
            "http://user@www.google.com:81/search.php?q1=test1",
            "http://user:pwd@www.google.com:81/search/for/search.php?q1=0&&test1&test2=value#top"
        };
        String[] accountURLs = {
            "*://www.google.com",
            "*://*google.com",
            "*://*.google.com/blah",
            "http://www.google.com/blah",
            "http://*.google.com/blah",
            "http://*.com/blah",
            "http://*google*/blah",
            "http://www.google.com:81/search/for/search.php",
            "*://*",
            "google",
            "",
        };
        URL currentURL;
        for(int i=0;i<currentURLs.length;i++) {
            try {
                System.out.println("Testing "+currentURLs[i]);
                currentURL = new URL(currentURLs[i]);
                System.out.println("Current URL\t\tAccount URL\t\tMatch");
                for(String accountURL : accountURLs) {
                    System.out.print(currentURLs[i]+"\t\t"+accountURL+"\t\t");
                    try {
                        System.out.println(new WildcardURL(accountURL).matches(currentURL));
                    } catch(Exception ex2) {
                        System.out.println("Error parsing:"+accountURL);
                    }
                }
            } catch(Exception ex) {
                System.out.println("Error parsing:"+currentURLs[i]);
            }
            System.out.println("\n");
        }

        long start = System.currentTimeMillis();
        int i;
        for(i = 0;i<2000;i++) {
            for(int j=0;j<currentURLs.length;j++) {
                try {
                    currentURL = new URL(currentURLs[j]);
                    for(String accountURL : accountURLs) {
                        try {
                            if(new WildcardURL(accountURL).matches(currentURL)) {
                                
                            };
                        } catch(Exception ex2) {}
                    }
                } catch(Exception ex) {}
            }
        }
        long millis = System.currentTimeMillis()-start;
        int numChecks = (i*currentURLs.length*accountURLs.length);
        System.out.println("Completed "+numChecks+" match checks in "+millis+"ms - Avg = "+new java.math.BigDecimal((millis/(double)numChecks)).setScale(3,java.math.BigDecimal.ROUND_HALF_UP)+"ms/check");
    }
}
